package http;

import java.net.HttpURLConnection;
import java.net.URL;

/**
 * Created by yangxianming on 2015-06-11.
 */
public class RequestGet implements RequestMethodImpl {
    HttpURLConnection conn = null;
    String urlFull = null;
    Header header = null;

    RequestGet(HttpURLConnection conn, String urlFull, Header header) {
        this.conn = conn;
        this.urlFull = urlFull;
        this.header = header;
    }


    @Override
    public HttpURLConnection sendData(Object waitSendData) throws Exception{
        String data = (String)waitSendData;
        if (data != "") {
            urlFull = urlFull + "?" + data;
        }

        URL url = new URL(urlFull);
        conn = (HttpURLConnection) url.openConnection();
        header.setHeader(conn);
        conn.setInstanceFollowRedirects(false);
        conn.connect();

        return conn;
    }
}
